package com.lanxin.oa.fiancial.controller;

import com.lanxin.bean.BxInformaltype;
import com.lanxin.oa.fiancial.service.ExpenseService;
import com.lanxin.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/expense")
public class ExpenseController {

    @Autowired
    private ExpenseService expenseService;

    @RequestMapping("/selectBxInfo")
    public ModelAndView selectBxInfo(Integer page, Integer pageSize) {
        PageBean<BxInformaltype> pageBean = expenseService.getDeptPage(page, pageSize);
        ModelAndView mv = new ModelAndView();
        mv.addObject("pageBean", pageBean);
        mv.setViewName("../view/fiancial/listbxinfo.jsp");
        return mv;
    }

    @RequestMapping("/deleteBxInfo")
    public ModelAndView deleteBxInfo(Integer oid) {
        ModelAndView mv = new ModelAndView();
        expenseService.deleteBxInfo(oid);
        mv.setViewName("redirect:/expense/selectBxInfo");
        return mv;
    }

    @RequestMapping("/toUpdatebxInfo")
    public ModelAndView toUpdatebxInfo(Integer oid){
        ModelAndView mv=new ModelAndView();
        BxInformaltype bxInfor=expenseService.BxInforById(oid);
        mv.addObject("bxInfor",bxInfor);
        mv.setViewName("../view/fiancial/editbxinfop.jsp");
        return mv;
    }

    @RequestMapping("/AddBxInfo")
    public ModelAndView AddBxInfo(BxInformaltype bxInfor) {
        ModelAndView mv = new ModelAndView();
        expenseService.editBxInfo(bxInfor);
        mv.setViewName("redirect:/expense/selectBxInfo");// 重定向到查询方法里
        return mv;
    }

    @RequestMapping("/checkBxInfoName")
    @ResponseBody
    public Map<String,Boolean> checkBxInfoName(String name, Integer oid){
        System.out.println(name+"  "+oid);
        Map<String,Boolean> map=new HashMap<String, Boolean>();
        boolean b=expenseService.selectByBxInfoNameService(name,oid);
        if(!b){
            map.put("valid", true);
            return map;
        }
        map.put("valid", false);
        return map;
    }

    @RequestMapping("/updateBxInforState")
    @ResponseBody
    public boolean updateBxInforState(Integer  oid,String isActice){
        boolean b=expenseService.updateBxInforState(oid,isActice);
        return b;
    }

}
